package com.yun.newBlog.blog.controller;

import com.yun.newBlog.blog.common.LoginUtils;
import com.yun.newBlog.blog.vo.LoginFailResponseVo;
import com.yun.newBlog.blog.vo.LoginSuccessResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.RememberMeAuthenticationToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.social.security.SocialAuthenticationToken;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;
import tk.mybatis.spring.annotation.MapperScan;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.Principal;

@RestController
@Slf4j
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ProviderSignInUtils providerSignInUtils;

    /**
     * 判断是否登录
     * @return
     */
    @RequestMapping("/succeed")
    public LoginSuccessResponseVo isLogin(HttpServletRequest request, HttpServletResponse response){

        LoginSuccessResponseVo loginResponseVo = LoginUtils.isLogin();

        return loginResponseVo;
    }

    @RequestMapping("/failed")
    public LoginFailResponseVo failed(){

        log.info("登录失败！");

        LoginFailResponseVo loginFailResponseVo = new LoginFailResponseVo();
        loginFailResponseVo.setErrMsg("登录失败：用户名或密码错误");
        return loginFailResponseVo;
    }

}
